package com.mycompany.app.hr.security.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.mycompany.app.common.audit.modification.model.AuditEmbeddedObject;

@SuppressWarnings("unchecked")
@Entity
@Table(name = "s_resource")
public class SystemResource {

    @Id
    @Column(name = "resource_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "resource_name")
    private String resourceName;

    @Column(name = "resource_string")
    private String resourceString;

    @Column(name = "resource_type_code")
    private String resourceTypeCode;

    @Column(name = "is_active")
    private Boolean isActive;

    @ManyToMany(mappedBy = "resources", cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
    private Set<SystemPermission> permissions = new HashSet<SystemPermission>(0);

    @Embedded
    private AuditEmbeddedObject auditEmbeddedObject = new AuditEmbeddedObject();

    // ===================================
    @Override
    public String toString() {

        return ToStringBuilder.reflectionToString(this,
                ToStringStyle.SHORT_PREFIX_STYLE);
    }

    // ===================================

    public Long getId() {

        return id;
    }

    public void setId(Long id) {

        this.id = id;
    }

    public String getResourceName() {

        return resourceName;
    }

    public void setResourceName(String resourceName) {

        this.resourceName = resourceName;
    }

    public String getResourceString() {

        return resourceString;
    }

    public void setResourceString(String resourceString) {

        this.resourceString = resourceString;
    }

    public String getResourceTypeCode() {

        return resourceTypeCode;
    }

    public void setResourceTypeCode(String resourceTypeCode) {

        this.resourceTypeCode = resourceTypeCode;
    }

    public AuditEmbeddedObject getAuditEmbeddedObject() {

        return auditEmbeddedObject;
    }

    public void setAuditEmbeddedObject(AuditEmbeddedObject auditEmbeddedObject) {

        this.auditEmbeddedObject = auditEmbeddedObject;
    }

    public Boolean getIsActive() {

        return isActive;
    }

    public void setIsActive(Boolean isActive) {

        this.isActive = isActive;
    }

    public Set<SystemPermission> getPermissions() {

        return permissions;
    }

    public void setPermissions(Set<SystemPermission> permissions) {

        this.permissions = permissions;
    }

}
